#ifndef __Infrared_h
#define __Infrared_h

#include <Arduino.h>

// define infrared action pin 4
#define INFRARED_ACTION_PIN 12

#define SerialInf Serial

// The actions
typedef enum {
  INFRARED_ACTION_ANYBODY = 1,  // 
  INFRARED_ACTION_NOBODY = 0,   // 
} 
InfraredActions;

// callback function
#if defined(ESP8266) || defined(ESP32)
#include <functional>
#define INFRARED_CALLBACK_SIGNATURE std::function<void(unsigned int)> callback
#else
#define INFRARED_CALLBACK_SIGNATURE void (*callback)(unsigned int)
#endif

class Infrared
{

public:
    Infrared(); //构造函数
    void setup();
    void loop();
    void check();
    void setNobodyTimeout(int timeout);
    int getValue();
    Infrared& setCallback(INFRARED_CALLBACK_SIGNATURE);

private:
    INFRARED_CALLBACK_SIGNATURE;
    InfraredActions action = INFRARED_ACTION_NOBODY;
    long _check_last;
    int _value;
    int _nobody_timeout=5;
    long _nobody_last;
    bool _nobody_flag=false;
};

#endif